package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Calendar implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	private boolean publicc;

	@OneToMany(cascade = CascadeType.ALL)
	private List<Event> events;
	
	@OneToOne(cascade = CascadeType.PERSIST)
	private User owner;
	
	public Calendar() {
		this.events = new LinkedList<Event>();
	}
	
	public Calendar(User owner) {
		this();
		this.owner = owner;
	}

	public List<Event> getEvents() {
		return this.events;
	}
	
	public void setEvents(List<Event> events) {
		this.events = events;
	}

	public void addEvent(Event e) {
		this.events.add(e);
	}

	public void deleteEvent(Event e) {
		this.events.remove(e);
	}

	public boolean isPublic() {
		return publicc;
	}

	public int getId() {
		return id;
	}

	public void setPublic(boolean publicc) {
		this.publicc = publicc;
	}
	
	public User getOwner() {
		return owner;
	}
}
